# include <bits/stdc++.h>

const int N=400010,INF=0x3f3f3f3f;

inline int read(void){
	int res,f=1;
	char c;
	while((c=getchar())<'0'||c>'9')
		if(c=='-') f=-1;
	res=c-48;
	while((c=getchar())>='0'&&c<='9')
		res=res*10+c-48;
	return res*f;
}

int n,m;

std::vector <std::pair <int,int> > G[N];
std::set <int> S;

bool vis[N];

inline bool bfs(void){
	std::fill(vis+1,vis+1+n,false);
	std::queue <int> q;
	q.push(1),vis[1]=true;
	
	int cnt=0;
	while(!q.empty()){
		int i=q.front();
		q.pop(),++cnt;
		for(auto eg:G[i]){
			int j=eg.first,id=eg.second;
			if(S.count(id)) continue;
			if(!vis[j]) vis[j]=true,q.push(j);
		}
	}
	return cnt==n;
}

int du[N];


std::set <int> T;

inline void gosub(void){
	std::queue <int> q;
	for(int i=1;i<=n;++i) if(du[i]==1) q.push(i);
	while(!q.empty()){
		int i=q.front();
		q.pop();
		for(auto eg:G[i]){
			int j=eg.first;
			--du[j];
			if(du[j]==1) q.push(j);
		}		
	}
	
	for(int i=1;i<=n;++i) for(auto eg:G[i]){
		int j=eg.first;
		if(du[i]==2&&du[j]==2) T.insert(eg.second);
	}
	
	int qq=read();
	
	while(qq--){
		S.clear();
		for(int k=read();k;--k) S.insert(read());
		if(S.size()>1) puts("NO");
		else if(T.count(*S.begin())) puts("YES");
		else puts("NO");
	}	
	
	return;
}

int main(void){
	freopen("graph.in","r",stdin);
	freopen("graph.out","w",stdout);
	
	n=read(),m=read();
	for(int i=1;i<=m;++i){
		int u=read(),v=read();
		++du[u],++du[v];
		G[u].emplace_back(v,i),G[v].emplace_back(u,i);
	}
	
	if(m==n&&(n>3000||m>3000)) gosub(),exit(0);
	
	int q=read();
	
	while(q--){
		S.clear();
		for(int k=read();k;--k) S.insert(read());
		
		if(bfs()) puts("YES");
		else puts("NO");
		
	}

	return 0;
}